#include <REGX52.H>
#include "Timer0.h"
#include "Delay.h"
#include "Key.h"
#include "INTRINS.h"
//void Timer0_Init(void){
////	TMOD = 0x01;	//0000 0001
////	TMOD = TMOD&0xF0;	//把TMOD 的低四位置0, 高四位不变
//	TMOD &= 0xF0;
////	TMOD = TMOD|0x01;	//把把TMOD 的最低位 置1, 高四位不变
//	TMOD |= 0x01;
//	TF0 = 0;
//	TR0 = 1;
//	TH0 = 64535/256;
//	TL0 = 64535%256;
//	//中断导通
//	ET0 = 1;	//导通中断
//	EA = 1; 	//导通总中断
//	//设置中断优先级
//	PT0 = 0;	//设置优先级
//}

unsigned char KeyNum,Led_Mode;

void main(void){
	P2 = 0xFE;
	Timer0_Init();
	while(1){
		KeyNum = Key();
		if(KeyNum){
			if(KeyNum == 1){
				Led_Mode++;
				if(Led_Mode>=2)
					Led_Mode = 0;
			}
		}
		
	}
}


void Timer0_Rountine() interrupt 1
{
	static unsigned int T0_Count;
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	T0_Count++;
	if(T0_Count>=500){
		T0_Count = 0;
		//P2_0 = ~P2_0;
		if(Led_Mode == 0)
			P2 = _crol_(P2, 1);
		if(Led_Mode == 1)
			P2 = _cror_(P2, 1);
	}
	
}

